package com.dycx.api.controller.manage.cms;


import com.dycx.cms.dto.KeywordDTO;
import com.dycx.cms.service.KeywordService;
import com.dycx.common.RestResponse;
import com.dycx.common.annotation.WriterLog;
import com.dycx.common.enums.BizTypeEnum;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;


/**
 * 关键字(Keyword)表控制层
 *
 * @author wuzongbin
 * @since 2023-05-24 11:46:34
 */
@RestController
@RequestMapping(value = "/manage/cms/keyword")
public class KeywordController {
    /**
     * 服务对象
     */
    @Resource
    private KeywordService keywordService;


    /**
     * 添加
     **/
    @WriterLog(logTitle = "添加关键字" )
    @PostMapping("/add")
    public RestResponse<?> add(@RequestBody @Valid KeywordDTO dto) {
        Integer id = keywordService.add(dto);
        return id > 0 ? RestResponse.success(id) : RestResponse.fail();
    }

    /**
     * 修改
     **/
    @WriterLog(logTitle = "修改关键字" )
    @PostMapping("/edit")
    public RestResponse<?> edit(@RequestBody @Valid KeywordDTO dto) {
        return keywordService.edit(dto) ? RestResponse.success() : RestResponse.fail();
    }


    /**
     * 查询详细
     **/
    @GetMapping("/getInfo")
    public RestResponse<?> getInfo(int id) {
        return RestResponse.success(keywordService.getInfo(id));
    }

    /**
     * 分页
     **/
    @PostMapping("/getPage")
    public RestResponse<?> getPage(@RequestBody KeywordDTO dto) {
        return RestResponse.success(keywordService.getPage(dto));
    }

    /**
     * 刪除
     **/
    @WriterLog(logTitle = "删除关键字" )
    @GetMapping("/delete")
    public RestResponse<?> delete(int id) {
        return keywordService.delete(id) ? RestResponse.success() : RestResponse.fail();
    }
}

